<template>
  <el-container>
    <el-header class="lich-header">
      <Navbar v-bind:user="user" v-bind:page_type="page_type"/>
    </el-header>
    <el-main>
      <el-row :gutter="5">
        <el-col :xl="{span: 16, offset: 4}" :lg="{span: 18, offset: 3}" :md="{span: 20, offset: 2}"
                :sm="{span: 22, offset: 1}"
                :xa="{span: 24, offset: 0}" style="margin-bottom: 20px;">
          <el-alert
            v-if="this.msg !== ''"
            :title="this.msg"
            type="error">
          </el-alert>
          <el-card style="text-align: center">
            <span>请使用Shell添加用户，删除用户或者重置用户密码</span>
            <br/>
            <el-image src="/admin.png"></el-image>
          </el-card>
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>
  import Navbar from '~/components/Navbar.vue'

  let _c = require('~/assets/config')

  export default {
    components: {
      Navbar
    },
    async asyncData({req, redirect, $axios}) {
      let opt = {};
      let _h = _c.API_HOST;
      if (process.server) {
        opt.headers = {
          "Cookie": req.headers.cookie + ";"
        };
      } else {
        $axios.defaults.withCredentials = true;
      }
      let {user} = await $axios.$get(`${_h}/user/islogin`, opt);
      let u;
      if (user === null || user === undefined) {
        redirect('/');
      } else {
        u = {
          isLogin: true,
          isAdmin: user.is_admin,
          userName: user.name,
          userId: user.id
        }
      }
      let _p = {
        _a: true,
        _b: false
      };
      return {
        msg: '', user: u, page_type: _p
      }
    }
  }
</script>

<style>
  .lich-header {
    text-align: right;
  }
</style>
